﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.TcCommands.TcCheckoutCheckin.CCoTcCheckoutCheckinBaseCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.TcCommands.TcCheckoutCheckin.PrivateImplementationDetails;
using EngineeringInternalExtension;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Utilities;


namespace DnProcessSimulateCommands.TcCommands.TcCheckoutCheckin;

public abstract class CCoTcCheckoutCheckinBaseCmd : TxButtonCommand
{
  protected CApTcCheckoutCheckinEnabler _enabler;

  protected Dictionary<string, string> GetErrorCodes()
  {
    return new Dictionary<string, string>(1)
    {
      {
        "TCSOACLIENT_PARTIAL_ERROR_DETAILS",
        this.ErrWindowInnerTitle
      }
    };
  }

  protected Hashtable GetErrorStackWarnings()
  {
    Dictionary<string, string[]> d = new Dictionary<string, string[]>();
    Dictionary<string, string> errorCodes = this.GetErrorCodes();
    foreach (string key in errorCodes.Keys)
    {
      if (TxErrorStack.Contains(key))
      {
        ArrayList allParameters = TxErrorStack.GetAllParameters(key);
        IList<string> source = (IList<string>) new List<string>();
        foreach (IList<string> stringList in allParameters)
        {
          if (stringList != null)
          {
            if (stringList.Count == 1)
              source.Add(stringList[0]);
            else if (stringList.Count == 2)
            {
              string str = string.Format(StringTable.TC_CHECKOUTCHECKIN_OBJECT_NAME_ERROR, (object) stringList[0]);
              source.Add(str + stringList[1]);
            }
            else if (stringList.Count == 3)
            {
              string str = string.Format(StringTable.TC_CHECKOUTCHECKIN_OBJECT_NAME_ID_ERROR, (object) stringList[0], (object) stringList[1]);
              source.Add(str + stringList[2]);
            }
          }
        }
        if (source.Count > 0)
          d.Add(errorCodes[key], source.ToArray<string>());
      }
    }
    return new Hashtable((IDictionary) d);
  }

  protected virtual void ShowSuccessMessage()
  {
  }

  protected void ShowExecutionResult()
  {
    Hashtable errorStackWarnings = this.GetErrorStackWarnings();
    if (errorStackWarnings.Count > 0)
      TxErrorWindow.ShowDialogEx(this.Name, this.ErrWindowSubTitle, new Hashtable(), errorStackWarnings, false, true, false, 50);
    else
      this.ShowSuccessMessage();
  }

  protected virtual void ExecuteSpecificCommand(object cmdParams)
  {
  }

  public virtual void Execute(object cmdParams)
  {
    if (!CApTcCIOUtil.IsCurrentTcVersionCompatible(this.Name))
      return;
    this.ExecuteSpecificCommand(cmdParams);
  }

  protected virtual string ErrWindowSubTitle => "";

  protected virtual string ErrWindowInnerTitle => "";

  public virtual string Category => StringTable.TC_CHECKOUTCHECKIN_CMD_CATEGORY;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this._enabler;
}
